#include "attribute.h"

#include "namespace.h"

using namespace std;

XmlAttribute::XmlAttribute(char* key, char* value) : mKey(key), mValue(value) {
	size_t nsSeparator = mKey.find_first_of(':');
	
	if (nsSeparator != string::npos) {
		mNamespace.assign(mKey.substr(0, nsSeparator));
		mKey.assign(mKey.substr(nsSeparator+1));
	}
}

XmlAttribute::~XmlAttribute() {
	// Nothing to do here
}

void XmlAttribute::setKey(string key) {
	mKey.assign(key);
}

void XmlAttribute::setValue(string value) {
	mValue.assign(value);
}

void XmlAttribute::setNamespace(Namespace ns) {
	mNamespace = ns;
}
	
string XmlAttribute::getKey() {
	return mKey;
}

string XmlAttribute::getValue() {
	return mValue;
}

Namespace XmlAttribute::getNamespace() {
	return mNamespace;
}

void XmlAttribute::print(ostream& out) {
	out << " ";
	
	if (!mNamespace.empty()) {
		out << mNamespace << ":";
	}
	out << mKey << "=\"" << mValue << "\"";
}
